<template>
	<xh-list-container ref="pageList" title="裁剪铺布列表" :request="request" :columns="columns" rowKey="id">
		<template v-slot="scope">
			<xh-list-item v-for="(item, index) in scope.data" :item-data="item" :index="index" :key="item.id"
				:columns="columns" @clickBtns="handleClickBtns" :buttons="[
          {
            text: '编辑',
            key: 'edit',
            color: 'primary',
          },
          {
            text: '删除',
            key: 'delete',
            color: 'error',
          },
        ]" />
		</template>
	</xh-list-container>
</template>

<script>
	import {
		getCuttingLayingFabricList,
		deleteCuttingLayingFabric,
		editCuttingLayingFabric,
	} from "@/api/purchase/fabric.js";
	import {
		LayingFabricTypeEnum
	} from '@/utils/constant';
	export default {
		name: "cuttingLayingFabric",
		data() {
			return {
				request: getCuttingLayingFabricList,
				columns: [{
						label: "裁剪日期",
						key: "cuttingDate",
						searchType: "daterange",
						searchOrder: 1,
					},
					{
						label: "裁剪编号",
						key: "cuttingCode",
						searchType: "text",
						searchOrder: 1,
					},
					{
						label: "产品名称",
						key: "productName",
						search: false,
					},
					{
						label: "状态",
						key: "status",
						search: false,
						valueMapList: LayingFabricTypeEnum,
					}
				],
			};
		},
		onShow() {
			this.$refs.pageList?._query();
		},
		methods: {
			handleClickBtns(btnKey, item, index) {
				if (btnKey === "delete") {
					this.handleDeleteItem(item, index);
				} else if (btnKey === "edit") {
					this.$nav.navigateTo(
						"/subProductionManage/cuttingLayingFabric/addForm",
						item
					);
				}
			},
			handleDeleteItem(item) {
				const {
					id
				} = item;
				this.$modal.confirm("确定删除吗？").then(() => {
					deleteCuttingLayingFabric(id).then(() => {
						this.$modal.msgSuccess("删除成功！");
						this.$refs.pageList?._query();
					});
				});
			},
		},
	};
</script>